home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume9 / tttt2 / patch1 < prev   
Encoding:
Internet Message Format  |  1990-05-21  |  6.3 KB

  1. Path: uunet!zephyr.ens.tek.com!tekred!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v09i048:  tttt2 - tic-tac-toc-toe with wraparound edges (V2), Patch1
  5. Message-ID: <5553@tekred.CNA.TEK.COM>
  6. Date: 8 May 90 00:47:16 GMT
  7. Sender: news@tekred.CNA.TEK.COM
  8. Lines: 235
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: Eric Lechner <lechner@ucscb.ucsc.edu>
  12. Posting-number: Volume 9, Issue 48
  13. Archive-name: tttt2/Patch1
  14. Patch-To: tttt2: Volume 9, Issue 36
  15.  
  16. [From the author:]
  17. [[This patch fixes a small bug that would let the computer
  18. player occasionally move on squares that already had
  19. pieces, which it shouldn't have done.
  20.  
  21. It also now uses "rand()" instead of "random()" so it'll
  22. compile straight off on systemV machines, and has a define
  23. if your curses package uses "crmode()" instead of "cbreak()".]]
  24.  
  25.     [I made a slight change to ifdef the rand/random code
  26.      to use random/lrand48/rand, depending on the define.  -br]
  27.  
  28. #! /bin/sh
  29. # This is a shell archive.  Remove anything before this line, then unpack
  30. # it by saving it into a file and typing "sh file".  To overwrite existing
  31. # files, type "sh file -c".  You can also feed this as standard input via
  32. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  33. # will see the following message at the end:
  34. #        "End of shell archive."
  35. # Contents:  patches01
  36. # Wrapped by billr@saab on Mon May  7 08:53:55 1990
  37. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  38. if test -f 'patches01' -a "${1}" != "-c" ; then 
  39.   echo shar: Will not clobber existing file \"'patches01'\"
  40. else
  41. echo shar: Extracting \"'patches01'\" \(4361 characters\)
  42. sed "s/^X//" >'patches01' <<'END_OF_FILE'
  43. X*** tttt.c.orig    Wed Apr 11 17:33:26 1990
  44. X--- tttt.c    Mon May  7 08:43:34 1990
  45. X***************
  46. X*** 41,46 ****
  47. X--- 41,55 ----
  48. X  #define FALSE    0
  49. X  #endif
  50. X  
  51. X+ #ifdef BSD
  52. X+ # define rand    random
  53. X+ # define srand    srandom
  54. X+ #else
  55. X+ /* Current versions of System V */
  56. X+ # define rand    lrand48        /* comment this out if you only have rand() */
  57. X+ # define srand    srand48        /* comment this out if you only have srand() */
  58. X+ #endif
  59. X+ 
  60. X  char board [4][4];        /* this is the playing board */
  61. X  int pieces;
  62. X  int randomness;            /* whether the computer uses randomness */
  63. X***************
  64. X*** 143,153 ****
  65. X  
  66. X      initscr();
  67. X      savetty();
  68. X      cbreak();
  69. X      noecho();
  70. X  
  71. X      signal(SIGINT,quit);
  72. X!     srandom(getpid() * (1 + getuid()));
  73. X  
  74. X      clear();
  75. X  
  76. X--- 152,166 ----
  77. X  
  78. X      initscr();
  79. X      savetty();
  80. X+ #ifdef CRMODE
  81. X+     crmode();
  82. X+ #else
  83. X      cbreak();
  84. X+ #endif
  85. X      noecho();
  86. X  
  87. X      signal(SIGINT,quit);
  88. X!     srand(getpid());
  89. X  
  90. X      clear();
  91. X  
  92. X***************
  93. X*** 391,404 ****
  94. X  int computer_move(type)
  95. X  int type;
  96. X  {
  97. X!     int bestrow = 0, bestcol = 0, i, j;
  98. X!     int bestrank = 0, numbest = 0, rank, numrank;
  99. X          /* rank == the rank score */
  100. X          /* num == the number of times the score happened */
  101. X  
  102. X      for (i=0; i<4; i++) {
  103. X          for (j=0; j<4; j++) {
  104. X              getrank(type,i,j,&rank,&numrank);
  105. X              if (rank > bestrank) {
  106. X                  bestrow = i;
  107. X                  bestcol = j;
  108. X--- 404,420 ----
  109. X  int computer_move(type)
  110. X  int type;
  111. X  {
  112. X!     int bestrow, bestcol, i, j;
  113. X!     int bestrank, numbest, rank, numrank;
  114. X          /* rank == the rank score */
  115. X          /* num == the number of times the score happened */
  116. X  
  117. X+     bestrow = bestcol = bestrank = numbest = 0;
  118. X+ 
  119. X      for (i=0; i<4; i++) {
  120. X          for (j=0; j<4; j++) {
  121. X              getrank(type,i,j,&rank,&numrank);
  122. X+             if (rank == 0) continue;
  123. X              if (rank > bestrank) {
  124. X                  bestrow = i;
  125. X                  bestcol = j;
  126. X***************
  127. X*** 411,417 ****
  128. X                      bestrank = rank;
  129. X                      numbest = numrank;
  130. X                  } else if (numrank == numbest) {
  131. X!                     if ((random() % 2) && randomness) {
  132. X                          bestrow = i;
  133. X                          bestcol = j;
  134. X                          bestrank = rank;
  135. X--- 427,433 ----
  136. X                      bestrank = rank;
  137. X                      numbest = numrank;
  138. X                  } else if (numrank == numbest) {
  139. X!                     if ((rand() % 2) && randomness) {
  140. X                          bestrow = i;
  141. X                          bestcol = j;
  142. X                          bestrank = rank;
  143. X***************
  144. X*** 435,443 ****
  145. X      this ranks a move location in order of "preference".
  146. X  
  147. X      the strategy is to not let the opponent get lots in a row.
  148. X      ever.
  149. X  
  150. X- 
  151. X      rows, columns, and diagonals get treated independently, and
  152. X      the "best" rank of them all is considered.
  153. X  */
  154. X--- 451,459 ----
  155. X      this ranks a move location in order of "preference".
  156. X  
  157. X      the strategy is to not let the opponent get lots in a row.
  158. X+ 
  159. X      ever.
  160. X  
  161. X      rows, columns, and diagonals get treated independently, and
  162. X      the "best" rank of them all is considered.
  163. X  */
  164. X***************
  165. X*** 450,456 ****
  166. X      *numrank = 0;
  167. X  
  168. X      /* if already taken, this isn't a good spot */
  169. X!     if (board[row][col]) return;
  170. X  
  171. X      /* check across */
  172. X      countx = counto = 0;
  173. X--- 466,472 ----
  174. X      *numrank = 0;
  175. X  
  176. X      /* if already taken, this isn't a good spot */
  177. X!     if (board[row][col] != EMPTY) return;
  178. X  
  179. X      /* check across */
  180. X      countx = counto = 0;
  181. X***************
  182. X*** 490,496 ****
  183. X  
  184. X      /* add one, so that even no blocks still shows as a valid move    */
  185. X      /* and return the rank for this move                */
  186. X!     *rank++;
  187. X  }
  188. X  
  189. X  /*
  190. X--- 506,512 ----
  191. X  
  192. X      /* add one, so that even no blocks still shows as a valid move    */
  193. X      /* and return the rank for this move                */
  194. X!     ++(*rank);
  195. X  }
  196. X  
  197. X  /*
  198. X*** Makefile.orig    Wed Apr 11 17:33:24 1990
  199. X--- Makefile    Mon May  7 08:52:48 1990
  200. X***************
  201. X*** 2,7 ****
  202. X--- 2,13 ----
  203. X  #
  204. X  # edit as necessary, then make
  205. X  
  206. X+ # CRMODE: if your version of curses uses "crmode()"
  207. X+ #         instead of "cbreak()", define CRMODE here.
  208. X+ # BSD: if your OS supports random() and srandom()
  209. X+ #FLAGS = -DCRMODE
  210. X+ FLAGS =
  211. X+ 
  212. X  # where the executable will go
  213. X  BINDIR = /usr/games
  214. X  
  215. X***************
  216. X*** 15,21 ****
  217. X  LIBS = -lcurses -ltermcap
  218. X  
  219. X  tttt: tttt.c
  220. X!     cc $(CFLAGS) -o tttt tttt.c $(LIBS)
  221. X  
  222. X  install: tttt tttt.man
  223. X      cp tttt $(BINDIR)/tttt
  224. X--- 21,27 ----
  225. X  LIBS = -lcurses -ltermcap
  226. X  
  227. X  tttt: tttt.c
  228. X!     cc $(CFLAGS) $(FLAGS) -o tttt tttt.c $(LIBS)
  229. X  
  230. X  install: tttt tttt.man
  231. X      cp tttt $(BINDIR)/tttt
  232. X*** /dev/null    Mon May  7 08:50:00 1990
  233. X--- patchlevel.h    Mon May  7 08:53:24 1990
  234. X***************
  235. X*** 0 ****
  236. X--- 1 ----
  237. X+ #define PATCHLEVEL    1
  238. END_OF_FILE
  239. if test 4361 -ne `wc -c <'patches01'`; then
  240.     echo shar: \"'patches01'\" unpacked with wrong size!
  241. fi
  242. # end of 'patches01'
  243. fi
  244. echo shar: End of shell archive.
  245. exit 0
  246.